home *** CD-ROM | disk | FTP | other *** search
/ PC Users 8 / Cd Pc Users extra 8.iso / prog / inst / firstimp / vcimpres.z / scroll.frm (.txt) < prev    next >
Encoding:
Visual Basic Form  |  1997-11-07  |  9.0 KB  |  251 lines

  1. VERSION 5.00
  2. Object = "{335C3C4F-E3F2-11D0-87E8-00A0C903B29D}#5.0#0"; "VCFI5.OCX"
  3. Begin VB.Form Form1 
  4.    Caption         =   "Form1"
  5.    ClientHeight    =   7095
  6.    ClientLeft      =   4035
  7.    ClientTop       =   2205
  8.    ClientWidth     =   7005
  9.    LinkTopic       =   "Form1"
  10.    PaletteMode     =   1  'UseZOrder
  11.    ScaleHeight     =   7095
  12.    ScaleWidth      =   7005
  13.    Begin VB.HScrollBar HScroll1 
  14.       Height          =   255
  15.       Left            =   120
  16.       TabIndex        =   3
  17.       Top             =   6840
  18.       Width           =   6915
  19.    End
  20.    Begin VtChartLib.VtChart VtChart1 
  21.       Height          =   5655
  22.       Left            =   120
  23.       TabIndex        =   2
  24.       Top             =   1080
  25.       Width           =   6855
  26.       _ExtentX        =   12091
  27.       _ExtentY        =   9975
  28.       _0              =   $"scroll.frx":0000
  29.       _1              =   $"scroll.frx":0405
  30.       _2              =   $"scroll.frx":080B
  31.       _3              =   $"scroll.frx":0C10
  32.       _4              =   $"scroll.frx":1015
  33.       _5              =   $"scroll.frx":141A
  34.       _6              =   $"scroll.frx":1820
  35.       _7              =   $"scroll.frx":1C25
  36.       _8              =   $"scroll.frx":202B
  37.       _count          =   9
  38.       _ver            =   1
  39.    End
  40.    Begin VB.Label lblinfo 
  41.       Alignment       =   2  'Center
  42.       Appearance      =   0  'Flat
  43.       BackColor       =   &H80000005&
  44.       BackStyle       =   0  'Transparent
  45.       Caption         =   "Information"
  46.       ForeColor       =   &H80000008&
  47.       Height          =   255
  48.       Left            =   0
  49.       TabIndex        =   1
  50.       Top             =   840
  51.       Width           =   6915
  52.    End
  53.    Begin VB.Label lblTitle 
  54.       Alignment       =   2  'Center
  55.       Caption         =   "Dow Jones Average"
  56.       BeginProperty Font 
  57.          Name            =   "Times New Roman"
  58.          Size            =   24
  59.          Charset         =   0
  60.          Weight          =   400
  61.          Underline       =   0   'False
  62.          Italic          =   0   'False
  63.          Strikethrough   =   0   'False
  64.       EndProperty
  65.       Height          =   615
  66.       Left            =   0
  67.       TabIndex        =   0
  68.       Top             =   120
  69.       Width           =   6915
  70.    End
  71.    Begin VB.Menu mnuChartTypeHead 
  72.       Caption         =   "&Chart Type"
  73.       Begin VB.Menu mnuChartType 
  74.          Caption         =   "2D Line"
  75.          Index           =   0
  76.       End
  77.       Begin VB.Menu mnuChartType 
  78.          Caption         =   "2D Area"
  79.          Index           =   1
  80.       End
  81.       Begin VB.Menu mnuChartType 
  82.          Caption         =   "3D Line"
  83.          Index           =   2
  84.       End
  85.       Begin VB.Menu mnuChartType 
  86.          Caption         =   "3D Area"
  87.          Index           =   3
  88.       End
  89.       Begin VB.Menu mnuChartType 
  90.          Caption         =   "3D Step"
  91.          Index           =   4
  92.       End
  93.    End
  94.    Begin VB.Menu mnuSetDaysVisible 
  95.       Caption         =   "&Set Days Visible!"
  96.    End
  97. Attribute VB_Name = "Form1"
  98. Attribute VB_GlobalNameSpace = False
  99. Attribute VB_Creatable = False
  100. Attribute VB_PredeclaredId = True
  101. Attribute VB_Exposed = False
  102. Option Explicit
  103. Option Base 1
  104. Dim DJData() As Double
  105. Dim gNumDataRows%
  106. Sub SetInfoLabel(offset%)
  107.    lblinfo.Caption = " Dow Jones Average on " & _
  108.       Format(DJData(HScroll1.Value + offset, 1), "d mmmm yyyy") & _
  109.       " was " & DJData(HScroll1.Value + offset, 2)
  110. End Sub
  111. Sub ShowView(startingAt%)
  112.    Dim i%, numRows%, min!, max!, temp#
  113.    Dim numLabels%, label$
  114.    numRows = HScroll1.LargeChange
  115.    '' If the user has scrolled to the end of the data, change
  116.    '' the startingAt value so the entire chart can be viewed.
  117.    '' This catches the case where the user has large window
  118.    '' and wants to scroll to the end.
  119.    If startingAt > 1 And startingAt > gNumDataRows - numRows Then
  120.       startingAt = gNumDataRows - numRows
  121.    End If
  122.    VtChart1.RowCount = numRows
  123.    '' The dimmensions of the array must match the dimmensions
  124.    '' of the chart you want to fill. You must always use a 2D
  125.    '' array even if you are copying in one row of data.
  126.    ReDim theData(numRows, 1) As Double
  127.    max = 0
  128.    min = 10000
  129.    For i = 1 To numRows
  130.       temp = DJData(i + startingAt, 2)
  131.       theData(i, 1) = temp
  132.       max = IIf(temp > max, temp, max)
  133.       min = IIf(temp < min, temp, min)
  134.    Next i
  135.    VtChart1.CopyDataFromArray 1, 1, numRows, 1, theData
  136.    '' AutoScale will have a minimum at zero. We set min
  137.    '' and max manually here
  138.    VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Maximum = Int((max + 20) / 10) * 10
  139.    VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Minimum = Int((min - 20) / 10) * 10
  140.    '' Clear any old datapoint labels
  141.    Dim DataPoint As Object
  142.    With VtChart1.Plot.SeriesCollection.Item(1)
  143.       For Each DataPoint In .DataPoints
  144.          DataPoint.DataPointLabel.ResetCustomLabel
  145.       Next DataPoint
  146.    End With
  147.    '' Set a new label for only the last datapoint
  148.    With VtChart1.Plot.SeriesCollection.Item(1).DataPoints.Item(numRows).DataPointLabel
  149.       .LocationType = VtChLabelLocationTypeCenter
  150.       .Text = Format(DJData(startingAt + numRows, 1), "m/d/yy")
  151.       .LineStyle = VtChLabelLineStyleStraight
  152.    End With
  153.    SetInfoLabel IIf(startingAt + numRows + 1 > gNumDataRows, gNumDataRows - HScroll1.Value, numRows)
  154. End Sub
  155. Private Sub Form_Load()
  156.    Dim numRows%, numCols%, col1Text$, col2Text$
  157.    Dim i%, j%, junk&
  158.    Open App.Path & "\djave.txt" For Input As #1
  159.    Input #1, numRows, numCols, col1Text, col2Text
  160.    ReDim DJData(numRows, numCols) As Double
  161.    For i = 1 To numRows
  162.       Input #1, DJData(i, 1), DJData(i, 2)
  163.    Next i
  164.    Close #1
  165.    '' Size the scrollbar and the chart
  166.    gNumDataRows = numRows
  167.    HScroll1.Left = 60
  168.    HScroll1.min = 1
  169.    HScroll1.max = numRows
  170.    HScroll1.LargeChange = 20
  171.    VtChart1.Left = 60
  172.    VtChart1.RowCount = 20
  173.    VtChart1.Plot.Axis(VtChAxisIdY).ValueScale.Auto = False
  174.    VtChart1.Plot.Axis(VtChAxisIdY).Labels.Item(1).Format = "#,##0"
  175.    ShowView HScroll1.Value
  176. End Sub
  177. Private Sub Form_Resize()
  178.    VtChart1.Repaint = False
  179.    lblTitle.Width = ScaleWidth
  180.    lblinfo.Width = ScaleWidth
  181.    VtChart1.Width = ScaleWidth - 120
  182.    VtChart1.Height = ScaleHeight - HScroll1.Height _
  183.       - lblinfo.Height - lblTitle.Height - 210
  184.    HScroll1.Width = ScaleWidth - 120
  185.    HScroll1.Top = ScaleHeight - HScroll1.Height - 60
  186.    VtChart1.Repaint = True
  187. End Sub
  188. Private Sub HScroll1_Change()
  189.    '' This prevents the user from scrolling into a dead area
  190.    '' where a change in scrollbar produces no change in the chart.
  191.    '' This can happen if the scrollbar is dragged to the end of
  192.    '' the chart and the user clicks on the arrow towards the
  193.    '' beginning of the chart.
  194.    If HScroll1.Value + HScroll1.LargeChange > HScroll1.max Then
  195.       HScroll1.Value = HScroll1.max - HScroll1.LargeChange
  196.    Else
  197.       ShowView HScroll1.Value
  198.    End If
  199. End Sub
  200. Private Sub mnuChartType_Click(Index As Integer)
  201.    Dim i%
  202.    For i = 0 To 4
  203.       mnuChartType(i).Checked = False
  204.    Next i
  205.    mnuChartType(Index).Checked = True
  206.    VtChart1.Plot.SeriesCollection.Item(1).Pen.Width = 2
  207.    Select Case Index
  208.       Case 0
  209.          VtChart1.chartType = VtChChartType2dLine
  210.          VtChart1.Plot.SeriesCollection.Item(1).Pen.Width = 0
  211.       Case 1
  212.          VtChart1.chartType = VtChChartType2dArea
  213.       Case 2
  214.          VtChart1.chartType = VtChChartType3dLine
  215.       Case 3
  216.          VtChart1.chartType = VtChChartType3dArea
  217.       Case 4
  218.          VtChart1.chartType = VtChChartType3dStep
  219.    End Select
  220. End Sub
  221. Private Sub mnuSetDaysVisible_Click()
  222.    Dim title$, msg$, retval$, default$, result$
  223.    Let title = "Number of Days in Plot"
  224.    Let msg = "Enter a number between 10 and " & gNumDataRows
  225.    default = Str(VtChart1.RowCount)
  226.    result = InputBox(msg, title, default)
  227.    While StrComp(result, "") <> 0 And (Val(result) < 10 Or Val(result) > gNumDataRows)
  228.       MsgBox "Value must be between 10 and " & gNumDataRows
  229.       result = InputBox(msg, title, default)
  230.    Wend
  231.    If StrComp(result, "") <> 0 Then
  232.       HScroll1.LargeChange = Val(result)
  233.       ShowView HScroll1.Value
  234.    End
  235. End Sub
  236. Private Sub VtChart1_AxisLabelSelected(axisID As Integer, AxisIndex As Integer, labelSetIndex As Integer, LabelIndex As Integer, MouseFlags As Integer, Cancel As Integer)
  237.    Cancel = True
  238. End Sub
  239. Private Sub VtChart1_AxisSelected(axisID As Integer, AxisIndex As Integer, MouseFlags As Integer, Cancel As Integer)
  240.    Cancel = True
  241. End Sub
  242. Private Sub VtChart1_AxisTitleSelected(axisID As Integer, AxisIndex As Integer, MouseFlags As Integer, Cancel As Integer)
  243.    Cancel = True
  244. End Sub
  245. Private Sub VtChart1_ChartSelected(MouseFlags As Integer, Cancel As Integer)
  246.    Cancel = True
  247. End Sub
  248. Private Sub VtChart1_FootnoteSelected(MouseFlags As Integer, Cancel As Integer)
  249.    Cancel = True
  250. End Sub
  251.